<template>
  <div>
    <div>
      <div class="adminInput">
        <div class="admin-in">
          <el-input
            v-model="input"
            @input="inputText"
            placeholder="请输入要查找的游戏"
          ></el-input>
        </div>
      </div>

      <div>
        <el-table :data="tableData" v-loading="loading" style="width: 100%">
          <el-table-column type="expand">
            <template slot-scope="props">
              <el-form label-position="left" inline class="demo-table-expand">
                <el-form-item label="游戏评分">
                  <span>{{ props.row.giScore }}</span>
                </el-form-item>
                <el-form-item label="游戏Logo">
                  <img class="admin-foodimg" :src="props.row.giLogo" alt="" />
                </el-form-item>
                <el-form-item label="开发商">
                  <span>{{ props.row.gjDeveloper }}</span>
                </el-form-item>
                <el-form-item label="运营商">
                  <span>{{ props.row.gjOperator }}</span>
                </el-form-item>
                <el-form-item label="地区">
                  <span>{{ props.row.giArea }}</span>
                </el-form-item>
                <el-form-item label="状态">
                  <span>{{ props.row.giState }}</span>
                </el-form-item>
                <el-form-item label="游戏介绍">
                  <span>{{ props.row.giIntroduce }}</span>
                </el-form-item>
                <el-form-item label="游戏详情">
                  <span v-html="props.row.giDetails"> </span>
                </el-form-item>
                <el-form-item label="游戏简介">
                  <span v-html="props.row.giTitle"> </span>
                </el-form-item>
                <el-form-item label="游戏热度">
                  <span v-html="props.row.giviews"> </span>
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column label="游戏 ID" prop="giId"> </el-table-column>
          <el-table-column label="游戏名称" prop="giName"> </el-table-column>
          <el-table-column label="游戏类别" prop="gtName"> </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="handleEdit(scope.row)"
                >编辑</el-button
              >
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.row)"
                >修改状态</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <div class="admin-fenye">
          <el-pagination
            background
            layout="prev, pager, next"
            :total="total"
            :page-size="7"
            :currentPage="curPage"
            @current-change="page"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getGameInformations,
  delGaemInformation,
  getGameInformationLike,
} from "../../network/admin";

export default {
  name: "GameList",
  data() {
    return {
      tableData: [],
      input: "",
      curPage: 1,
      total: 0,
      loading: true,
      state: "",
    };
  },

  created() {
    this.getMessage();
  },

  methods: {
    getMessage() {
      if (this.$route.query.page != undefined) {
        this.curPage = this.$route.query.page;
      }
      getGameInformations(this.curPage).then((res) => {
        this.tableData = res.data.data.list;
        this.total = res.data.data.total;
        this.loading = false;
      });
    },

    handleDelete(row) {
      if (row.giState == 0) {
        this.state = 1;
      } else {
        this.state = 0;
      }
      delGaemInformation(row.giId, this.state).then((res) => {
        console.log(res);
        this.$alert("修改完成", "提示", {
          confirmButtonText: "确定",
          callback: () => {
            this.getMessage();
          },
        });
      });
    },

    inputText() {
      this.curPage = 1;
      this.$router.push({
        path: "gamelist",
        query: {
          page: 1,
        },
      });
      getGameInformationLike(this.input, this.curPage).then((res) => {
        this.tableData = res.data.data.list;
        this.total = res.data.data.total;
        this.loading = false;
        console.log(res);
      });
    },

    //跳转修改页面
    handleEdit(row) {
      this.$router.push({
        path: "modifygame",
        query: {
          giId: row.giId,
        },
      });
    },

    page(currentPage) {
      this.curPage = currentPage;
      this.loading = true;
      this.$router.push({
        path: "gamelist",
        query: {
          page: currentPage,
        },
      });
      this.getMessage();
    },
  },
};
</script>

<style>
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
.admin-foodimg {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 0.1rem;
}
.adminUpadteFood {
  font-size: 0.1rem;
  margin-left: 0.8rem;
}

.adminUpdate-item {
  font-size: 0.1rem;
  display: flex;
  align-items: center;
  margin-top: 0.25rem;
}

.adminUpdate-item img {
  width: 1.2rem;
  height: 1rem;
}

.adminTextarea {
  width: 5rem;
}

.adminFood-name {
  width: 1rem;
}

.adminWanCheng {
  margin-left: 2.5rem;
  margin-top: 0.2rem;
}

.adminWanCheng button {
  width: 1.5rem;
}
</style>